package com.dongdongshop.controller;

import com.dongdongshop.data.Result;
import com.dongdongshop.domain.vo.ContentVO;
import com.dongdongshop.service.ContentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("content")
@CrossOrigin   //跨域
@Slf4j
@RefreshScope   //自动监听配置文件
public class ContentController {

    @Autowired
    private ContentService contentService;

    //根据广告类型查询全部广告
    @GetMapping("contentList")
    public Result contentList(@RequestParam(defaultValue = "0") Long cid){
        List<ContentVO> contentVOList = contentService.contentList(cid);
        return Result.OK().setData(contentVOList);
    }

    //增加广告
    @PostMapping("add")
    public Result addContent(@RequestBody ContentVO contentVO){
        return contentService.addContent(contentVO);
    }

    //根据id查询/回显
    @GetMapping("selectById")
    public Result selectById(@RequestParam Long id){
        ContentVO contentVO = contentService.selectById(id);
        return Result.OK().setData(contentVO);
    }

    //修改
    @PutMapping("update")
    public Result updateContent(@RequestBody ContentVO contentVO){
        return contentService.update(contentVO);
    }

    //删除
    @DeleteMapping("delete")
    public Result delete(@RequestParam Long id){
        return contentService.delete(id);
    }

    //批量删除
    @DeleteMapping("deleteContent")
    public Result deleteContent(@RequestBody List<Long> id){
        return contentService.deleteContent(id);
    }

}
